/*
 * @ : Copyright (c) 2021 Phytium Information Technology, Inc. 
 *  
 * SPDX-License-Identifier: Apache-2.0.
 * 
 * @Date: 2021-07-26 16:28:18
 * @LastEditTime: 2021-08-03 17:17:55
 * @Description:  This files is for static config of i2c ctrl 
 * 
 * @Modify History: 
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 * 1.0   Zhugengyu   2021/8/3   init
 */
#include "parameters.h"
#include "dw_i2c.h"

/* default configs of i2c ctrl */
static I2cConfig I2cConfigTbl[I2C_INSTANCE_NUM] =
{
    {
        .instanceId = I2C_INSTANCE_0,
        .baseAddr = I2C_0_BASEADDR,
        .irqNum = I2C_0_INTR_IRQ,
        .irqPrority = 0,
        .workMode = I2C_MASTER,
        .busSpeed = I2C_SPEED_STANDARD_RATE,
        .refClk = I2C_REF_CLK_HZ,
        .rxThres = 0,
        .txThres = 0,
        .use7bitAddr = TRUE,  
        .instanceName = "I2C-0"      
    },

    {
        .instanceId = I2C_INSTANCE_1,
        .baseAddr = I2C_1_BASEADDR,
        .irqNum = I2C_1_INTR_IRQ,
        .irqPrority = 1,
        .workMode = I2C_SLAVE,
        .busSpeed = I2C_SPEED_STANDARD_RATE,
        .refClk = I2C_REF_CLK_HZ,
        .rxThres = 0,
        .txThres = 0,        
        .use7bitAddr = TRUE,
        .instanceName = "I2C-1"
    },

    {
        .instanceId = I2C_INSTANCE_2,
        .baseAddr = I2C_2_BASEADDR,
        .irqNum = I2C_2_INTR_IRQ,
        .irqPrority = 0,
        .workMode = I2C_MASTER,
        .busSpeed = I2C_SPEED_STANDARD_RATE,
        .refClk = I2C_REF_CLK_HZ,
        .rxThres = 0,
        .txThres = 0,
        .use7bitAddr = TRUE,  
        .instanceName = "I2C-2"      
    },    

    {
        .instanceId = I2C_INSTANCE_3,
        .baseAddr = I2C_3_BASEADDR,
        .irqNum = I2C_3_INTR_IRQ,
        .irqPrority = 0,
        .workMode = I2C_MASTER,
        .busSpeed = I2C_SPEED_STANDARD_RATE,
        .refClk = I2C_REF_CLK_HZ,
        .rxThres = 0,
        .txThres = 0,
        .use7bitAddr = TRUE,  
        .instanceName = "I2C-3"      
    }     
};

/**
 * @name: I2cLookupConfig
 * @msg: get i2c configs by id
 * @return {*}
 * @param {u32} instanceId, id of i2c ctrl
 */
const I2cConfig *I2cLookupConfig(u32 instanceId)
{
    I2cConfig *pConfig = NULL;
    u32 index;

    for (index = 0; index < (u32)I2C_INSTANCE_NUM; index++)
    {
        if (I2cConfigTbl[index].instanceId == instanceId)
        {
            pConfig = &I2cConfigTbl[index];
            break;
        }
    }

    return (I2cConfig *)pConfig;  
}